home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / var / lib / dpkg / info / dpkg.postinst < prev    next >
Encoding:
Text File  |  2007-03-06  |  4.4 KB  |  181 lines

  1. #!/bin/sh -e
  2. # This script can be called in the following ways:
  3. #
  4. # After the package was installed:
  5. #    <postinst> configure <old-version>
  6. #
  7. #
  8. # If prerm fails during upgrade or fails on failed upgrade:
  9. #    <old-postinst> abort-upgrade <new-version>
  10. #
  11. # If prerm fails during removal:
  12. #    <old-postinst> abort-remove
  13. #
  14. # If prerm fails during deconfiguration of a package:
  15. #    <postinst> abort-deconfigure in-favour <new-package> <version>
  16. #           removing <old-package> <version>
  17. #
  18. # If prerm fails during replacement due to conflict:
  19. #    <postinst> abort-remove in-favour <new-package> <version>
  20.  
  21.  
  22. # Create the database files if they don't already exist
  23. create_database() {
  24.     admindir=/var/lib/dpkg
  25.  
  26.     for file in diversions statoverride status; do
  27.     if [ ! -f "$admindir/$file" ]; then
  28.         touch "$admindir/$file"
  29.     fi
  30.     done
  31. }
  32.  
  33.  
  34. # Move the info directory from /usr/info to /usr/share/info
  35. move_info_directory() {
  36.     if [ -d /usr/info ] && [ ! -L /usr/info ] \
  37.     && [ -f /usr/info/dir ] && [ ! -L /usr/info/dir ]
  38.     then
  39.     echo "Moving /usr/info/dir to /usr/share/info/dir ..."
  40.     mv /usr/info/dir /usr/share/info/dir
  41.     if [ -f /usr/info/dir.old ]; then
  42.         mv /usr/info/dir.old /usr/share/info/dir.old
  43.     fi
  44.     fi
  45. }
  46.  
  47.  
  48. # Remove the /usr/info symlinks we used to generate
  49. remove_info_symlink() {
  50.     if [ -L /usr/info ]; then
  51.     echo "Removing /usr/info symlink ..."
  52.     rm /usr/info
  53.     elif [ -L /usr/info/dir ]; then
  54.     echo "Removing /usr/info/dir symlink ..."
  55.     rm /usr/info/dir
  56.     fi
  57. }
  58.  
  59.  
  60. # Repair damage to /usr/info caused by broken install-info
  61. fix_damaged_info() {
  62.     echo -n "
  63. The version of dpkg you're upgrading from had a problem with the
  64. install-info program used to maintain the /usr/info/dir file.  It may
  65. have corrupted the file, for example by placing new entries for the
  66. menu in it before the \`* Menu' line (thus making them ineffective) or
  67. by creating several identical sections.
  68.  
  69. I can try to sort these problems out, but beware that this process is
  70. not guaranteed not to mess up a dir file which has things that look
  71. like menu entries in the introductory paragraphs.  The distributed dir
  72. files do not do this, so if you haven't edited /usr/info/dir it's
  73. almost certainly safe to say \"yes\" to the next question.
  74.  
  75. If you say \"no\" you may wish to check and/or edit /usr/info/dir yourself.
  76.  
  77. Try to check/repair /usr/info/dir automatically ? [y/n] "
  78.     read response
  79.     case "$response" in
  80.     [yY]*|"")
  81.             echo "Checking/repairing /usr/info/dir ..."
  82.         cleanup-info --unsafe
  83.         ;;
  84.     *)
  85.         echo "OK, leaving it alone."
  86.         ;;
  87.     esac
  88. }
  89.  
  90.  
  91. # Remove stop links from runlevels which also have start links
  92. # Dates back to the days when update-rc.d was part of dpkg.
  93. remove_duplicate_daemons() {
  94.     for lvl in 0 1 2 3 4 5 6; do
  95.     cd /etc/rc$lvl.d
  96.     for kill in K[0-9][0-9]*; do
  97.         if [ -n "`echo \"x$kill\" | tr -d 0-9A-Za-z_-`" ]; then
  98.         continue
  99.         fi
  100.  
  101.         start="`echo $kill | sed -e 's/^K/S/'`"
  102.         if ! [ -L $start ] && [ -L $kill ] \
  103.         || [ "`ls -Li $kill 2>/dev/null | awk '{print $1}'`" != \
  104.         "`ls -Li $start 2>/dev/null | awk '{print $1}'`" ]
  105.         then
  106.         continue
  107.         fi
  108.  
  109.         removes="$removes rc$lvl.d/$kill"
  110.     done
  111.     done
  112.  
  113.     if [ -n "$removes" ]; then
  114.     echo -n "
  115. Some daemons and similar services whose scripts have links in the
  116. /etc/rcN.d directories have both start (S) and stop (K) links in
  117. some runlevels.  Thus these services get stopped and immediately
  118. restarted at some runlevel changes, which is probably not what
  119. you want.
  120.  
  121. I can remove these probably-spurious K links if you like:
  122.   $removes
  123.  
  124. If you're not sure what to do, say \"no\", and then run delete them
  125. by hand later.
  126.  
  127. Shall I remove these links ? [y/n] "
  128.     read response
  129.     case "$response" in
  130.         [yY]*|"")
  131.                 echo "Removing duplicate K links ..."
  132.         cd /etc
  133.         rm $removes
  134.         ;;
  135.         *)
  136.             echo "OK, leaving them."
  137.         ;;
  138.     esac
  139.     fi
  140. }
  141.  
  142.  
  143. # Create log file and set default permissions if possible
  144. create_logfile() {
  145.     logfile=/var/log/dpkg.log
  146.     touch $logfile
  147.     chmod 640 $logfile
  148.     chown root:adm $logfile 2>/dev/null || chown 0:4 $logfile
  149. }
  150.  
  151.  
  152. case "$1" in
  153.     configure)
  154.     create_database
  155.     create_logfile
  156.  
  157.     case "$2" in
  158.         0.* | 1.0.* | 1.1.0 | 1.1.0[^0-9]* | '' )
  159.             remove_duplicate_daemons
  160.         ;;
  161.         1.1.6 | 1.1.6elf | 1.2.[0123] | 1.2.[0123]elf)
  162.             fix_damaged_info
  163.             ;;
  164.     esac
  165.  
  166.     move_info_directory
  167.     remove_info_symlink
  168.     ;;
  169.  
  170.     abort-upgrade|abort-deconfigure|abort-remove)
  171.     ;;
  172.  
  173.     *)
  174.     echo "$0 called with unknown argument \`$1'" 1>&2
  175.     exit 1
  176.     ;;
  177. esac
  178.  
  179.  
  180. exit 0
  181.